﻿<ResourceDictionary
	xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    x:Class="ExtendedGrid.Styles.DataGridGeneric"
	xmlns:ExtendedGridControl="clr-namespace:ExtendedGrid.ExtendedGridControl"
	xmlns:UserControls="clr-namespace:ExtendedGrid.UserControls" xmlns:Converter="clr-namespace:ExtendedGrid.Converter"
	xmlns:Base="clr-namespace:ExtendedGrid.Base" xmlns:Classes="clr-namespace:ExtendedGrid.Classes"
	xmlns:Primitives1="clr-namespace:ExtendedGrid.Microsoft.Windows.Controls.Primitives"
	xmlns:Controls="clr-namespace:ExtendedGrid.Microsoft.Windows.Controls">

    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="Brushes.xaml"/>
    </ResourceDictionary.MergedDictionaries>
    <Style x:Key="{x:Type Controls:DataGridRow}" TargetType="{x:Type Controls:DataGridRow}">
        <Setter Property="SnapsToDevicePixels" Value="true"/>
        <Setter Property="Validation.ErrorTemplate" Value="{x:Null}" />
        <Setter Property="ValidationErrorTemplate">
            <Setter.Value>
                <ControlTemplate>
                    <TextBlock Margin="2,0,0,0" VerticalAlignment="Center" Foreground="Red" Text="!" />
                </ControlTemplate>
            </Setter.Value>
        </Setter>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Controls:DataGridRow}">
                    <Border x:Name="DGR_Border"
                  Background="{TemplateBinding Background}"
                  BorderBrush="{TemplateBinding BorderBrush}"
                  BorderThickness="{TemplateBinding BorderThickness}"
                  SnapsToDevicePixels="True">
                        <Primitives1:SelectiveScrollingGrid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto"/>
                                <ColumnDefinition Width="*"/>
                            </Grid.ColumnDefinitions>

                            <Grid.RowDefinitions>
                                <RowDefinition Height="*"/>
                                <RowDefinition Height="Auto"/>
                            </Grid.RowDefinitions>

                            <Primitives1:DataGridCellsPresenter Grid.Column="1"
                                         ItemsPanel="{TemplateBinding ItemsPanel}"
                                         SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>

                            <Primitives1:DataGridDetailsPresenter  Primitives1:SelectiveScrollingGrid.SelectiveScrollingOrientation="{Binding RelativeSource={RelativeSource AncestorType={x:Type ExtendedGridControl:ExtendedDataGrid}}, Path=AreRowDetailsFrozen, Converter={x:Static Controls:DataGrid.RowDetailsScrollingConverter}, ConverterParameter={x:Static Controls:SelectiveScrollingOrientation.Vertical}}"
                                            Grid.Column="1" Grid.Row="1"
                                            Visibility="{TemplateBinding DetailsVisibility}" />

                            <Primitives1:DataGridRowHeader Primitives1:SelectiveScrollingGrid.SelectiveScrollingOrientation="Vertical"  Grid.RowSpan="2"
                                    Visibility="{Binding RelativeSource={RelativeSource AncestorType={x:Type ExtendedGridControl:ExtendedDataGrid}}, Path=HeadersVisibility, Converter={x:Static Controls:DataGrid.HeadersVisibilityConverter}, ConverterParameter={x:Static Controls:DataGridHeadersVisibility.Row}}"/>
                        </Primitives1:SelectiveScrollingGrid>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>


    <Style x:Key="GroupHeaderStyle" TargetType="{x:Type GroupItem}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type GroupItem}" >
                    <ControlTemplate.Resources>
                        <Style x:Key="ToggleButtonStyle"  TargetType="ToggleButton">
                            <Setter Property="Background" Value="Transparent"/>
                            <Setter Property="IsEnabled" Value="True" />
                            <Setter Property="IsTabStop" Value="False" />
                            <Setter Property="Cursor" Value="Hand"/>
                            <Setter Property="Template">
                                <Setter.Value>
                                    <ControlTemplate TargetType="ToggleButton">
                                        <Grid x:Name="Button" Margin="0,4,0,0" HorizontalAlignment="Right"
                               VerticalAlignment="Top" Width="16" Height="16">
                                            <Rectangle Stroke="{DynamicResource DynamicDefaultControlForegroundBrush}" HorizontalAlignment="Stretch"
                                   VerticalAlignment="Stretch" Width="Auto" Height="Auto"
                                   RadiusX="3" RadiusY="3" Fill="Transparent">
                                            </Rectangle>
                                            <Rectangle x:Name="CollapsedVisual" HorizontalAlignment="Left"
                                   VerticalAlignment="Top" Width="2" Height="8" RadiusX="0" Visibility="Collapsed"
                                   RadiusY="0" Fill="{DynamicResource DynamicDefaultControlForegroundBrush}" Margin="7,4,0,0" />
                                            <Rectangle RadiusX="0" RadiusY="0" Fill="{DynamicResource DynamicDefaultControlForegroundBrush}"
                                   HorizontalAlignment="Left" Margin="4,7,0,0"
                                   VerticalAlignment="Top" Width="8" Height="2" />
                                        </Grid>
                                        <ControlTemplate.Triggers>
                                            <Trigger Property="IsChecked" Value="False">
                                                <Setter TargetName="CollapsedVisual" Property="Visibility" Value="Visible"/>
                                            </Trigger>
                                        </ControlTemplate.Triggers>
                                    </ControlTemplate>

                                </Setter.Value>
                            </Setter>
                        </Style>
                        <Style x:Key="{x:Type Expander}"  TargetType="{x:Type Expander}">
                            <Setter Property="Foreground" Value="{DynamicResource DynamicDefaultControlForegroundBrush}"/>
                            <Setter Property="Background" Value="Transparent"/>
                            <Setter Property="Padding" Value="1"/>
                            <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
                            <Setter Property="VerticalContentAlignment" Value="Stretch"/>
                            <Setter Property="BorderBrush" Value="{DynamicResource DynamicSeperatorBrush}"/>
                            <Setter Property="BorderThickness" Value="1"/>
                            <Setter Property="Template">
                                <Setter.Value>
                                    <ControlTemplate TargetType="{x:Type Expander}">
                                        <Border BorderBrush="{DynamicResource DynamicSeperatorBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" CornerRadius="3" SnapsToDevicePixels="true">
                                            <DockPanel>

                                                <Border DockPanel.Dock="Top" BorderBrush="{DynamicResource DynamicSeperatorBrush}" BorderThickness="{TemplateBinding BorderThickness}">
                                                    <StackPanel Orientation="Horizontal">
                                                        <ToggleButton Style="{StaticResource ToggleButtonStyle}" x:Name="HeaderSite" ContentTemplate="{TemplateBinding HeaderTemplate}" ContentTemplateSelector="{TemplateBinding HeaderTemplateSelector}" Content="{TemplateBinding Header}"  Foreground="{TemplateBinding Foreground}" FontWeight="{TemplateBinding FontWeight}" FocusVisualStyle="{DynamicResource ExpanderHeaderFocusVisual}" FontStyle="{TemplateBinding FontStyle}" FontStretch="{TemplateBinding FontStretch}" FontSize="{TemplateBinding FontSize}" FontFamily="{TemplateBinding FontFamily}" HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" HorizontalAlignment="Left" IsChecked="{Binding IsExpanded, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" Margin="1" MinWidth="0" MinHeight="0" Padding="{TemplateBinding Padding}"  VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"/>
                                                        <TextBlock FontWeight="Bold" VerticalAlignment="Center" Text="{Binding RelativeSource={RelativeSource AncestorType=Expander}, Path=Header}"></TextBlock>
                                                    </StackPanel>

                                                </Border>

                                                <ContentPresenter x:Name="ExpandSite" DockPanel.Dock="Bottom" Focusable="false" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" Visibility="Collapsed" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
                                            </DockPanel>
                                        </Border>
                                        <ControlTemplate.Triggers>
                                            <Trigger Property="IsExpanded" Value="true">
                                                <Setter Property="Visibility" TargetName="ExpandSite" Value="Visible"/>
                                            </Trigger>
                                            <Trigger Property="IsEnabled" Value="false">
                                                <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
                                            </Trigger>
                                        </ControlTemplate.Triggers>
                                    </ControlTemplate>
                                </Setter.Value>
                            </Setter>
                        </Style>
                    </ControlTemplate.Resources>
                    <Expander IsExpanded="True" Header="{Binding Name}"  BorderBrush="{DynamicResource DynamicHeaderPressedBackgroundBrush}" BorderThickness="0,0.5,0.5,0" Margin="0,0,0,0" Expanded="ExpanderExpanded" Collapsed="ExpanderExpanded"
                          Background="{DynamicResource DynamicHeaderBackgroundBrush}" >

                        <ItemsPresenter />
                    </Expander>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
    <GroupStyle x:Key="CustomGroupStyle" ContainerStyle="{StaticResource GroupHeaderStyle}">
        <GroupStyle.Panel>
            <ItemsPanelTemplate>
                <!--<Primitives:DataGridRowsPresenter Margin="4,0,0,0" />-->
                <Classes:CustomDataGridRowsPresenter />
            </ItemsPanelTemplate>
        </GroupStyle.Panel>
    </GroupStyle>
    <Converter:RowSummariesValueConverter x:Key="RowSummariesValueConverter"></Converter:RowSummariesValueConverter>
    <Converter:RowSummaryVisibiltyConverter x:Key="RowSummaryVisibiltyConverter"></Converter:RowSummaryVisibiltyConverter>
    <Converter:RowSummariesClearButtonIsEnabledConverter x:Key="RowSummariesClearButtonIsEnabledConverter"></Converter:RowSummariesClearButtonIsEnabledConverter>

    <!-- Value converters -->
    <BooleanToVisibilityConverter x:Key="bool2VisibilityConverter" />
    <ContextMenu x:Key="DataGridHeaderColumnChooser" StaysOpen="True" HorizontalContentAlignment="Stretch" Width="Auto" HorizontalAlignment="Stretch">
        <MenuItem StaysOpenOnClick="True" HorizontalAlignment="Stretch" HorizontalContentAlignment="Stretch">
            <MenuItem.Header>
                <UserControls:ColumnChooserControl></UserControls:ColumnChooserControl>
            </MenuItem.Header>
        </MenuItem>
    </ContextMenu>

    <ContentControl x:Key="SortContenetControl">


        <StackPanel DockPanel.Dock="Right" VerticalAlignment="Center">
            <Path  Visibility="Visible"   Data="M0,0 L1,0 0.5,1 z" 
                                         Width="8" Height="6" Fill="{DynamicResource DynamicSortBrush}" Stretch="Fill" 
                                          RenderTransformOrigin="0.5,0.4" Tag="{x:Null}"/>

        </StackPanel>

    </ContentControl>
    <Style x:Key="ColumnHeaderRightGripperStyle" TargetType="{x:Type Thumb}">
        <Setter Property="Width" Value="8"/>
        <Setter Property="Background" Value="Transparent"/>
        <Setter Property="Cursor" Value="SizeWE"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Thumb}">
                    <Border Padding="{TemplateBinding Padding}"
							Background="{TemplateBinding Background}">
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
    <!-- DataGridColumnHeader Left Gripper Style -->
    <Style x:Key="ColumnHeaderLeftGripperStyle" 
		   BasedOn="{StaticResource ColumnHeaderRightGripperStyle}" 
		   TargetType="{x:Type Thumb}">
        <Setter Property="Width" Value="8"/>
        <Setter Property="Background" Value="Transparent"/>
        <Setter Property="Cursor" Value="SizeWE"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Thumb}">
                    <Border Name="Border"
							Padding="{TemplateBinding Padding}" 
							Background="{TemplateBinding Background}">
                        <Canvas>
                            <Line RenderOptions.EdgeMode="Aliased" Stroke="{DynamicResource DynamicHeaderBorderBrush}"
								  X1="7" Y1="{Binding ElementName=Border, Path=ActualHeight}"
								  X2="7" Y2="0"/>
                        </Canvas>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
    <!-- DataGridColumnHeader Style -->
    <Style x:Key="RowSummariesHeader" TargetType="{x:Type Primitives1:DataGridColumnHeader}">
        <Setter Property="Foreground" Value="{DynamicResource DynamicDefaultControlForegroundBrush}"/>
        <Setter Property="VerticalContentAlignment" Value="Center" />
        <Setter Property="Background" Value="{DynamicResource DynamicHeaderBackgroundBrush}"/>
        <Setter Property="BorderBrush" Value="{DynamicResource DynamicHeaderBorderBrush}" />
        <Setter Property="BorderThickness" Value="0,1,0,1" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Primitives1:DataGridColumnHeader}">
                    <Grid>
                        <Controls:DataGridHeaderBorder
                        x:Name="headerBorder"
                        IsHovered="{TemplateBinding IsMouseOver}"
                        IsPressed="{TemplateBinding IsPressed}"
                        IsClickable="{TemplateBinding CanUserSort}"
                        Background="{TemplateBinding Background}"
                        BorderBrush="{TemplateBinding BorderBrush}"
                        BorderThickness="{TemplateBinding BorderThickness}"
                        Padding ="{TemplateBinding Padding}"
                        SeparatorVisibility="Visible"
                        SeparatorBrush="{TemplateBinding SeparatorBrush}">
                            <Border BorderBrush="{DynamicResource DynamicHeaderBorderBrush}"
                                BorderThickness="1,0,0,0">
                                <ContentControl Margin="4,0,4,0" >
                                    <StackPanel >
                                        <StackPanel Orientation="Horizontal" x:Name="sumPanel">
                                            <TextBlock MinWidth="50" FontWeight="Bold">Sum=</TextBlock>
                                            <TextBlock x:Name="sumTextBlock">
                                                <TextBlock.Text>
                                                    <MultiBinding  Converter="{StaticResource RowSummariesValueConverter}" ConverterParameter="Sum">
                                                        <Binding RelativeSource="{RelativeSource Mode=FindAncestor, AncestorType=Primitives1:DataGridColumnHeader}"/>
                                                        <Binding RelativeSource="{RelativeSource Mode=FindAncestor, AncestorType=ExtendedGridControl:ExtendedDataGrid}" Path="RowSummariesTable"/>
                                                    </MultiBinding>
                                                </TextBlock.Text>
                                            </TextBlock>
                                        </StackPanel>
                                        <StackPanel Orientation="Horizontal">
                                            <TextBlock MinWidth="50" FontWeight="Bold">Average=</TextBlock>
                                            <TextBlock >
                                                <TextBlock.Text>
                                                    <MultiBinding  Converter="{StaticResource RowSummariesValueConverter}" ConverterParameter="Average">
                                                        <Binding RelativeSource="{RelativeSource Mode=FindAncestor, AncestorType=Primitives1:DataGridColumnHeader}"/>
                                                        <Binding RelativeSource="{RelativeSource Mode=FindAncestor, AncestorType=ExtendedGridControl:ExtendedDataGrid}" Path="RowSummariesTable"/>
                                                    </MultiBinding>
                                                </TextBlock.Text>
                                            </TextBlock>
                                        </StackPanel>
                                        <StackPanel Orientation="Horizontal">
                                            <TextBlock MinWidth="50" FontWeight="Bold">Count=</TextBlock>
                                            <TextBlock >
                                                <TextBlock.Text>
                                                    <MultiBinding  Converter="{StaticResource RowSummariesValueConverter}" ConverterParameter="Count">
                                                        <Binding RelativeSource="{RelativeSource Mode=FindAncestor, AncestorType=Primitives1:DataGridColumnHeader}"/>
                                                        <Binding RelativeSource="{RelativeSource Mode=FindAncestor, AncestorType=ExtendedGridControl:ExtendedDataGrid}" Path="RowSummariesTable"/>
                                                    </MultiBinding>
                                                </TextBlock.Text>
                                            </TextBlock>
                                        </StackPanel>
                                        <StackPanel Orientation="Horizontal">
                                            <TextBlock MinWidth="50" FontWeight="Bold">Min=</TextBlock>
                                            <TextBlock >
                                                <TextBlock.Text>
                                                    <MultiBinding  Converter="{StaticResource RowSummariesValueConverter}" ConverterParameter="Min">
                                                        <Binding RelativeSource="{RelativeSource Mode=FindAncestor, AncestorType=Primitives1:DataGridColumnHeader}"/>
                                                        <Binding RelativeSource="{RelativeSource Mode=FindAncestor, AncestorType=ExtendedGridControl:ExtendedDataGrid}" Path="RowSummariesTable"/>
                                                    </MultiBinding>
                                                </TextBlock.Text>
                                            </TextBlock>
                                        </StackPanel>
                                        <StackPanel Orientation="Horizontal">
                                            <TextBlock MinWidth="50" FontWeight="Bold">Max=</TextBlock>
                                            <TextBlock >
                                                <TextBlock.Text>
                                                    <MultiBinding  Converter="{StaticResource RowSummariesValueConverter}" ConverterParameter="Max">
                                                        <Binding RelativeSource="{RelativeSource Mode=FindAncestor, AncestorType=Primitives1:DataGridColumnHeader}"/>
                                                        <Binding RelativeSource="{RelativeSource Mode=FindAncestor, AncestorType=ExtendedGridControl:ExtendedDataGrid}" Path="RowSummariesTable"/>
                                                    </MultiBinding>
                                                </TextBlock.Text>
                                            </TextBlock>
                                        </StackPanel>
                                        <StackPanel Orientation="Horizontal">
                                            <TextBlock MinWidth="50" FontWeight="Bold">Smallest=</TextBlock>
                                            <TextBlock >
                                                <TextBlock.Text>
                                                    <MultiBinding  Converter="{StaticResource RowSummariesValueConverter}" ConverterParameter="Smallest">
                                                        <Binding RelativeSource="{RelativeSource Mode=FindAncestor, AncestorType=Primitives1:DataGridColumnHeader}"/>
                                                        <Binding RelativeSource="{RelativeSource Mode=FindAncestor, AncestorType=ExtendedGridControl:ExtendedDataGrid}" Path="RowSummariesTable"/>
                                                    </MultiBinding>
                                                </TextBlock.Text>
                                            </TextBlock>
                                        </StackPanel>
                                        <StackPanel Orientation="Horizontal">
                                            <TextBlock MinWidth="50" FontWeight="Bold">Largest=</TextBlock>
                                            <TextBlock >
                                                <TextBlock.Text>
                                                    <MultiBinding  Converter="{StaticResource RowSummariesValueConverter}" ConverterParameter="Largest">
                                                        <Binding RelativeSource="{RelativeSource Mode=FindAncestor, AncestorType=Primitives1:DataGridColumnHeader}"/>
                                                        <Binding RelativeSource="{RelativeSource Mode=FindAncestor, AncestorType=ExtendedGridControl:ExtendedDataGrid}" Path="RowSummariesTable"/>
                                                    </MultiBinding>
                                                </TextBlock.Text>
                                            </TextBlock>
                                        </StackPanel>
                                    </StackPanel>
                                </ContentControl>
                            </Border>
                        </Controls:DataGridHeaderBorder>
                        <Thumb x:Name="PART_LeftHeaderGripper"
							   HorizontalAlignment="Left"
							   Style="{StaticResource ColumnHeaderRightGripperStyle}"/>
                        <Thumb x:Name="PART_RightHeaderGripper"
							   HorizontalAlignment="Right"
							   Style="{StaticResource ColumnHeaderLeftGripperStyle}"/>

                    </Grid>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsMouseOver" Value="True">
                            <Setter TargetName="headerBorder" Property="Background"
                                Value="{DynamicResource DynamicHeaderHighlightedBackgoundBrush}" />
                        </Trigger>
                        <Trigger Property="IsPressed" Value="True">
                            <Setter TargetName="headerBorder" Property="Background"
                                Value="{DynamicResource DynamicHeaderPressedBackgroundBrush}" />
                        </Trigger>

                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>




    <!-- DataGridColumnHeader Style -->
    <Style x:Key="ColumnHeaderStyle" TargetType="{x:Type Primitives1:DataGridColumnHeader}">
        <Setter Property="Background" Value="{DynamicResource DynamicHeaderBackgroundBrush}"/>
        <Setter Property="BorderBrush" Value="{DynamicResource DynamicHeaderBorderBrush}" />
        <EventSetter Event="SizeChanged" Handler="ColumnSizeChanged"/>
        <Setter Property="VerticalContentAlignment" Value="Center" />
        <Setter Property="Background" Value="{DynamicResource DynamicHeaderBackgroundBrush}"/>
        <Setter Property="BorderBrush" Value="{DynamicResource DynamicHeaderBorderBrush}" />
        <Setter Property="BorderThickness" Value="0,1,0,1" />
        <Setter Property="ContextMenu" Value="{StaticResource DataGridHeaderColumnChooser}"/>
        <Setter Property="Height" Value="30"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Primitives1:DataGridColumnHeader}">
                    <Grid >
                        <Controls:DataGridHeaderBorder
							x:Name="headerBorder"
                            HorizontalAlignment="Stretch"
							SortDirection="{TemplateBinding SortDirection}"
							IsHovered="{TemplateBinding IsMouseOver}"
							IsPressed="{TemplateBinding IsPressed}"
							IsClickable="{TemplateBinding CanUserSort}"
							Background="{TemplateBinding Background}"
							BorderBrush="{TemplateBinding BorderBrush}"
							BorderThickness="{TemplateBinding BorderThickness}"
							Padding ="{TemplateBinding Padding}"
							SeparatorVisibility="{TemplateBinding SeparatorVisibility}"
							SeparatorBrush="{TemplateBinding SeparatorBrush}"
                            MouseDown="HeaderClickMouseDown">
                            <Border BorderBrush="{StaticResource HeaderInnerBorderBrush}" 
									BorderThickness="0,1,0,0">
                                <Border.Resources>
                                    <BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
                                </Border.Resources>
                                <DockPanel LastChildFill="True" >
                                    <Popup x:Name="popupDrag" StaysOpen="True" IsHitTestVisible="True" Placement="RelativePoint"  AllowsTransparency="False" IsOpen="False" MinWidth="150" MaxWidth="200" Tag="False">
                                        <StackPanel LostFocus="PopLostFocus" Focusable="True">
                                            <Button FontFamily="{TemplateBinding FontFamily}" FontSize="9" MinHeight="24" IsEnabled="False"   LostFocus="PopLostFocus" Click="ClearClicked" x:Name="btnClear">(Clear Filter)</Button>
                                            <Grid Visibility="{Binding RelativeSource={RelativeSource AncestorType=ExtendedGridControl:ExtendedDataGrid},Path=SearchAutoFilterVisibility}">
                                                <TextBlock Text="Search..." Foreground="DarkGray" Margin="3,0,0,0"
                                                    Visibility="{Binding ElementName=txtSearchAutoFilter, Path=Text.IsEmpty, 
                                                    Converter={StaticResource BooleanToVisibilityConverter}}" Background="White"/>
                                                <Border BorderBrush="DarkGray" BorderThickness="1">
                                                    <DockPanel LastChildFill="True">
                                                        <Image  DockPanel.Dock="Right" Height="20" Width="20" Source="../Images/search.jpg" RenderOptions.BitmapScalingMode="HighQuality" Panel.ZIndex="100"></Image>
                                                        <TextBox x:Name="txtSearchAutoFilter" Height="22"  HorizontalAlignment="Stretch" TextChanged="AutoFilterSearchTextChanged" Tag="{Binding RelativeSource={RelativeSource AncestorType=ExtendedGridControl:ExtendedDataGrid}}">
                                                            <TextBox.Resources>
                                                                <Style TargetType="TextBox">
                                                                    <Style.Triggers>
                                                                        <Trigger Property="Text" Value="{x:Null}">
                                                                            <Setter Property="Background" Value="Transparent"/>
                                                                        </Trigger>
                                                                        <Trigger Property="Text" Value="">
                                                                            <Setter Property="Background" Value="Transparent"/>
                                                                        </Trigger>
                                                                    </Style.Triggers>
                                                                </Style>
                                                            </TextBox.Resources>
                                                        </TextBox>
                                                    </DockPanel>
                                                </Border>
                                            </Grid>
                                            <ListBox x:Name="autoFilterList" FontFamily="{TemplateBinding FontFamily}" MaxHeight="350" VirtualizingStackPanel.IsVirtualizing="True" ScrollViewer.HorizontalScrollBarVisibility="Auto" ScrollViewer.VerticalScrollBarVisibility="Auto"
                                                     LostFocus="PopLostFocus">
                                                <ListBox.Resources>
                                                    <Style TargetType="{x:Type ListBoxItem}">
                                                        <Style.Triggers>
                                                            <DataTrigger Binding="{Binding Hide}" Value="True">
                                                                <Setter Property="Visibility" Value="Collapsed"/>
                                                            </DataTrigger>
                                                        </Style.Triggers>
                                                        
                                                    </Style>
                                                </ListBox.Resources>
                                                <ListBox.ItemTemplate>
                                                    <DataTemplate>
                                                        <CheckBox Foreground="{DynamicResource DynamicAutoFilterForegroundBrushBrush}" x:Name="chkBox" Margin="0"  FontSize="{Binding RelativeSource={RelativeSource AncestorType=ExtendedGridControl:ExtendedDataGrid},Path=AutoFilterFontSize}"  Content="{Binding Name}" IsChecked="{Binding IsChecked}" Checked="Checked" Unchecked="UnChecked" Tag="{Binding IsSelectAll}" />
                                                        <DataTemplate.Triggers>
                                                            <Trigger SourceName="chkBox" Property="Tag" Value="(Select All)">
                                                                <Setter TargetName="chkBox" Property="FontWeight" Value="Bold" />
                                                            </Trigger>
                                                        </DataTemplate.Triggers>
                                                    </DataTemplate>
                                                </ListBox.ItemTemplate>
                                            </ListBox>
                                        </StackPanel>
                                    </Popup>
                                    <Popup x:Name="sigmaDrag" StaysOpen="True" IsHitTestVisible="True" Placement="RelativePoint"   AllowsTransparency="False" IsOpen="False" MinWidth="150" MaxWidth="200" Tag="False">
                                        <StackPanel LostFocus="PopLostFocus" Focusable="True">
                                            <Button  FontFamily="{TemplateBinding FontFamily}" FontSize="9" MinHeight="24" Click="ClearSummaries"  LostFocus="PopSigmaLostFocus"  x:Name="btnSigmaClear">(Clear Summaries
                                                <Button.Tag>
                                                    <MultiBinding  Converter="{StaticResource RowSummariesClearButtonIsEnabledConverter}" ConverterParameter="Sum">
                                                        <Binding RelativeSource="{RelativeSource Mode=FindAncestor, AncestorType=Primitives1:DataGridColumnHeader}"/>
                                                        <Binding RelativeSource="{RelativeSource Mode=FindAncestor, AncestorType=ExtendedGridControl:ExtendedDataGrid}" Path="RowSummariesTable"/>
                                                    </MultiBinding>
                                                </Button.Tag>
                                            </Button>
                                            <ListBox x:Name="sigmaList"  FontFamily="{TemplateBinding FontFamily}" MaxHeight="350" VirtualizingStackPanel.IsVirtualizing="True" ScrollViewer.HorizontalScrollBarVisibility="Auto" ScrollViewer.VerticalScrollBarVisibility="Auto">
                                                <ListBox.ItemTemplate>
                                                    <DataTemplate>
                                                        <CheckBox  Foreground="{DynamicResource DynamicAutoFilterForegroundBrushBrush}" x:Name="chkBox" Margin="0" FontSize="9"  Content="{Binding Name}" IsChecked="{Binding IsChecked}" Checked="SigmaChecked" Unchecked="SigmaUnChecked" />
                                                    </DataTemplate>
                                                </ListBox.ItemTemplate>
                                            </ListBox>
                                        </StackPanel>
                                    </Popup>
                                    <ContentControl x:Name="autofilter" Background="{DynamicResource DynamicAutoFilterBrush}"  Focusable="True" Margin="0,0,2,0" MouseDown="AutoFilterMouseDown" MouseRightButtonDown="AutoFilterRightMouseDown"  Visibility="Collapsed" DockPanel.Dock="Right" Style="{x:Null}" VerticalAlignment="Center" BorderBrush="Transparent" BorderThickness="0" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" Loaded="AutoFilterGlphLoaded">

                                        <StackPanel Orientation="Horizontal" Background="{DynamicResource DynamicHeaderBackgroundBrush}">

                                            <Path Stroke="{DynamicResource DynamicSeperatorBrush}" StrokeThickness="1" Margin="0,0,3,0">
                                                <Path.Data>
                                                    <PathGeometry>
                                                        <PathGeometry.Figures>
                                                            <PathFigureCollection>
                                                                <PathFigure StartPoint="0,0">
                                                                    <PathFigure.Segments>
                                                                        <PathSegmentCollection>
                                                                            <LineSegment Point="0,15" />
                                                                        </PathSegmentCollection>
                                                                    </PathFigure.Segments>
                                                                </PathFigure>
                                                            </PathFigureCollection>
                                                        </PathGeometry.Figures>
                                                    </PathGeometry>
                                                </Path.Data>
                                            </Path>
                                            <Path Data="M0,0 L8,0 4,4Z" Fill="{DynamicResource AutoFilterBrush}" Stroke="Gray" VerticalAlignment="Center" HorizontalAlignment="Center"></Path>
                                            <Path Stroke="{DynamicResource DynamicSeperatorBrush}" StrokeThickness="1" Margin="3,0,0,0">
                                                <Path.Data>
                                                    <PathGeometry>
                                                        <PathGeometry.Figures>
                                                            <PathFigureCollection>
                                                                <PathFigure StartPoint="0,0">
                                                                    <PathFigure.Segments>
                                                                        <PathSegmentCollection>
                                                                            <LineSegment Point="0,15" />
                                                                        </PathSegmentCollection>
                                                                    </PathFigure.Segments>
                                                                </PathFigure>
                                                            </PathFigureCollection>
                                                        </PathGeometry.Figures>
                                                    </PathGeometry>
                                                </Path.Data>
                                            </Path>
                                        </StackPanel>
                                    </ContentControl>
                                    <ContentControl x:Name="sigma" Cursor="Hand" Margin="0,0,2,0" Opacity="0.5" MouseDown="SigmaMouseDown" MouseRightButtonDown="SigmaRightMouseDown" DockPanel.Dock="Right" Style="{x:Null}" VerticalAlignment="Center" BorderBrush="Transparent" BorderThickness="0" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch">
                                        <StackPanel Orientation="Horizontal">
                                            <Path Stroke="{DynamicResource DynamicSeperatorBrush}" StrokeThickness="1" Margin="0,0,1.2,0">
                                                <Path.Data>
                                                    <PathGeometry>
                                                        <PathGeometry.Figures>
                                                            <PathFigureCollection>
                                                                <PathFigure StartPoint="0,0">
                                                                    <PathFigure.Segments>
                                                                        <PathSegmentCollection>
                                                                            <LineSegment Point="0,15" />
                                                                        </PathSegmentCollection>
                                                                    </PathFigure.Segments>
                                                                </PathFigure>
                                                            </PathFigureCollection>
                                                        </PathGeometry.Figures>
                                                    </PathGeometry>
                                                </Path.Data>
                                            </Path>
                                            <ContentControl Height="12" Width="15" ContentTemplate="{DynamicResource SigmaContentTemplate}">

                                            </ContentControl>
                                            <!--<Image Height="12" Width="15" RenderOptions.BitmapScalingMode="HighQuality"  Tag="Sigma" Name="SigmaImage"/>-->
                                            <Path Stroke="{DynamicResource DynamicSeperatorBrush}" StrokeThickness="1" Margin="1.2,0,0,0">
                                                <Path.Data>
                                                    <PathGeometry>
                                                        <PathGeometry.Figures>
                                                            <PathFigureCollection>
                                                                <PathFigure StartPoint="0,0">
                                                                    <PathFigure.Segments>
                                                                        <PathSegmentCollection>
                                                                            <LineSegment Point="0,15" />
                                                                        </PathSegmentCollection>
                                                                    </PathFigure.Segments>
                                                                </PathFigure>
                                                            </PathFigureCollection>
                                                        </PathGeometry.Figures>
                                                    </PathGeometry>
                                                </Path.Data>
                                            </Path>
                                        </StackPanel>
                                    </ContentControl>
                                    <StackPanel DockPanel.Dock="Right" VerticalAlignment="Center">
                                        <Path x:Name="SortArrow"  Margin="0,0,7,0" Visibility="Visible"   Data="M0,0 L1,0 0.5,1 z" 
                                         Width="8" Height="6" Fill="{DynamicResource DynamicSortBrush}" Stretch="Fill" 
                                          RenderTransformOrigin="0.5,0.4" Tag="{x:Null}"/>
                                        <TextBlock x:Name="txtSortOrder" Foreground="{DynamicResource SortOrderForeGroundBrushBrush}" Margin="4.5,-10,7,0" FontSize="7" Visibility="Collapsed">1</TextBlock>
                                    </StackPanel>




                                    <TextBlock DockPanel.Dock="Left"
									Text="{Binding}" Margin="4,0,4,0"
									SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
									VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
									HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" />

                                </DockPanel>
                            </Border>

                        </Controls:DataGridHeaderBorder>

                        <Thumb x:Name="PART_LeftHeaderGripper"
							   HorizontalAlignment="Left"
							   Style="{StaticResource ColumnHeaderRightGripperStyle}"/>
                        <Thumb x:Name="PART_RightHeaderGripper"
							   HorizontalAlignment="Right"
							   Style="{StaticResource ColumnHeaderLeftGripperStyle}"/>
                    </Grid>
                    <ControlTemplate.Triggers>
                        <!--Auto Filter-->
                        <MultiTrigger>
                            <MultiTrigger.Conditions>
                                <Condition Property="IsMouseOver" Value="True"></Condition>
                                <Condition SourceName="autofilter"   Property="IsMouseOver" Value="False"></Condition>
                                <Condition SourceName="popupDrag"   Property="Tag" Value="False"></Condition>
                            </MultiTrigger.Conditions>
                            <Setter TargetName="autofilter" Property="ContentTemplate" >
                                <Setter.Value>
                                    <DataTemplate>
                                        <StackPanel Orientation="Horizontal" Background="Transparent">

                                            <Path Stroke="{DynamicResource DynamicSeperatorBrush}" StrokeThickness="1" Margin="0,0,3,0">
                                                <Path.Data>
                                                    <PathGeometry>
                                                        <PathGeometry.Figures>
                                                            <PathFigureCollection>
                                                                <PathFigure StartPoint="0,0">
                                                                    <PathFigure.Segments>
                                                                        <PathSegmentCollection>
                                                                            <LineSegment Point="0,15" />
                                                                        </PathSegmentCollection>
                                                                    </PathFigure.Segments>
                                                                </PathFigure>
                                                            </PathFigureCollection>
                                                        </PathGeometry.Figures>
                                                    </PathGeometry>
                                                </Path.Data>
                                            </Path>
                                            <Path Data="M0,0 L8,0 4,4Z" Fill="{DynamicResource AutoFilterBrush}" Stroke="Gray" VerticalAlignment="Center" HorizontalAlignment="Center"></Path>
                                            <Path Stroke="{DynamicResource DynamicSeperatorBrush}" StrokeThickness="1" Margin="3,0,0,0">
                                                <Path.Data>
                                                    <PathGeometry>
                                                        <PathGeometry.Figures>
                                                            <PathFigureCollection>
                                                                <PathFigure StartPoint="0,0">
                                                                    <PathFigure.Segments>
                                                                        <PathSegmentCollection>
                                                                            <LineSegment Point="0,15" />
                                                                        </PathSegmentCollection>
                                                                    </PathFigure.Segments>
                                                                </PathFigure>
                                                            </PathFigureCollection>
                                                        </PathGeometry.Figures>
                                                    </PathGeometry>
                                                </Path.Data>
                                            </Path>
                                        </StackPanel>
                                    </DataTemplate>
                                </Setter.Value>
                            </Setter>
                            <Setter TargetName="autofilter" Property="Visibility" Value="Visible"/>
                        </MultiTrigger>
                        <MultiTrigger>
                            <MultiTrigger.Conditions>
                                <Condition Property="IsMouseOver" Value="True"></Condition>
                                <Condition SourceName="autofilter"   Property="IsMouseOver" Value="True"></Condition>
                                <Condition SourceName="popupDrag"   Property="Tag" Value="False"></Condition>
                            </MultiTrigger.Conditions>
                            <Setter TargetName="autofilter" Property="ContentTemplate" 
									 >
                                <Setter.Value>
                                    <DataTemplate>
                                        <StackPanel Orientation="Horizontal" Background="Transparent">

                                            <Path Stroke="{DynamicResource DynamicSeperatorBrush}" StrokeThickness="1" Margin="0,0,3,0">
                                                <Path.Data>
                                                    <PathGeometry>
                                                        <PathGeometry.Figures>
                                                            <PathFigureCollection>
                                                                <PathFigure StartPoint="0,0">
                                                                    <PathFigure.Segments>
                                                                        <PathSegmentCollection>
                                                                            <LineSegment Point="0,15" />
                                                                        </PathSegmentCollection>
                                                                    </PathFigure.Segments>
                                                                </PathFigure>
                                                            </PathFigureCollection>
                                                        </PathGeometry.Figures>
                                                    </PathGeometry>
                                                </Path.Data>
                                            </Path>
                                            <Path Data="M0,0 L8,0 4,4Z" Fill="{DynamicResource AutoFilterDarkBrush}" Stroke="{DynamicResource AutoFilterDarkBrush}" VerticalAlignment="Center" HorizontalAlignment="Center"></Path>
                                            <Path Stroke="{DynamicResource DynamicSeperatorBrush}" StrokeThickness="1" Margin="3,0,0,0">
                                                <Path.Data>
                                                    <PathGeometry>
                                                        <PathGeometry.Figures>
                                                            <PathFigureCollection>
                                                                <PathFigure StartPoint="0,0">
                                                                    <PathFigure.Segments>
                                                                        <PathSegmentCollection>
                                                                            <LineSegment Point="0,15" />
                                                                        </PathSegmentCollection>
                                                                    </PathFigure.Segments>
                                                                </PathFigure>
                                                            </PathFigureCollection>
                                                        </PathGeometry.Figures>
                                                    </PathGeometry>
                                                </Path.Data>
                                            </Path>
                                        </StackPanel>
                                    </DataTemplate>
                                </Setter.Value>
                            </Setter>
                            <Setter TargetName="autofilter" Property="Visibility" Value="Visible"/>
                        </MultiTrigger>
                        <MultiTrigger>
                            <MultiTrigger.Conditions>
                                <Condition Property="IsMouseOver" Value="False"></Condition>
                                <Condition SourceName="autofilter"   Property="IsMouseOver" Value="False"></Condition>
                                <Condition SourceName="popupDrag"   Property="IsOpen" Value="True"></Condition>
                                <Condition SourceName="popupDrag"   Property="Tag" Value="False"></Condition>
                            </MultiTrigger.Conditions>
                            <Setter TargetName="autofilter" Property="ContentTemplate" 
									 >
                                <Setter.Value>
                                    <DataTemplate>
                                        <StackPanel Orientation="Horizontal" Background="{DynamicResource DynamicHeaderBackgroundBrush}">

                                            <Path Stroke="{DynamicResource DynamicSeperatorBrush}" StrokeThickness="1" Margin="0,0,3,0">
                                                <Path.Data>
                                                    <PathGeometry>
                                                        <PathGeometry.Figures>
                                                            <PathFigureCollection>
                                                                <PathFigure StartPoint="0,0">
                                                                    <PathFigure.Segments>
                                                                        <PathSegmentCollection>
                                                                            <LineSegment Point="0,15" />
                                                                        </PathSegmentCollection>
                                                                    </PathFigure.Segments>
                                                                </PathFigure>
                                                            </PathFigureCollection>
                                                        </PathGeometry.Figures>
                                                    </PathGeometry>
                                                </Path.Data>
                                            </Path>
                                            <Path Data="M0,0 L8,0 4,4Z" Fill="{DynamicResource AutoFilterDarkBrush}" Stroke="{DynamicResource AutoFilterDarkBrush}" VerticalAlignment="Center" HorizontalAlignment="Center"></Path>
                                            <Path Stroke="{DynamicResource DynamicSeperatorBrush}" StrokeThickness="1" Margin="3,0,0,0">
                                                <Path.Data>
                                                    <PathGeometry>
                                                        <PathGeometry.Figures>
                                                            <PathFigureCollection>
                                                                <PathFigure StartPoint="0,0">
                                                                    <PathFigure.Segments>
                                                                        <PathSegmentCollection>
                                                                            <LineSegment Point="0,15" />
                                                                        </PathSegmentCollection>
                                                                    </PathFigure.Segments>
                                                                </PathFigure>
                                                            </PathFigureCollection>
                                                        </PathGeometry.Figures>
                                                    </PathGeometry>
                                                </Path.Data>
                                            </Path>
                                        </StackPanel>
                                    </DataTemplate>
                                </Setter.Value>
                            </Setter>
                            <Setter TargetName="autofilter" Property="Visibility" Value="Visible"/>
                        </MultiTrigger>
                        <MultiTrigger>
                            <MultiTrigger.Conditions>
                                <Condition Property="IsMouseOver" Value="True"></Condition>
                                <Condition SourceName="popupDrag"   Property="IsOpen" Value="True"></Condition>
                                <Condition SourceName="popupDrag"   Property="Tag" Value="False"></Condition>
                            </MultiTrigger.Conditions>
                            <Setter TargetName="autofilter" Property="ContentTemplate" 
									 >
                                <Setter.Value>
                                    <DataTemplate>
                                        <StackPanel Orientation="Horizontal" Background="{DynamicResource DynamicHeaderHighlightedBackgoundBrush}">

                                            <Path Stroke="{DynamicResource DynamicSeperatorBrush}" StrokeThickness="1" Margin="0,0,3,0">
                                                <Path.Data>
                                                    <PathGeometry>
                                                        <PathGeometry.Figures>
                                                            <PathFigureCollection>
                                                                <PathFigure StartPoint="0,0">
                                                                    <PathFigure.Segments>
                                                                        <PathSegmentCollection>
                                                                            <LineSegment Point="0,15" />
                                                                        </PathSegmentCollection>
                                                                    </PathFigure.Segments>
                                                                </PathFigure>
                                                            </PathFigureCollection>
                                                        </PathGeometry.Figures>
                                                    </PathGeometry>
                                                </Path.Data>
                                            </Path>
                                            <Path Data="M0,0 L8,0 4,4Z" Fill="{DynamicResource AutoFilterDarkBrush}" Stroke="{DynamicResource AutoFilterDarkBrush}" VerticalAlignment="Center" HorizontalAlignment="Center"></Path>
                                            <Path Stroke="{DynamicResource DynamicSeperatorBrush}" StrokeThickness="1" Margin="3,0,0,0">
                                                <Path.Data>
                                                    <PathGeometry>
                                                        <PathGeometry.Figures>
                                                            <PathFigureCollection>
                                                                <PathFigure StartPoint="0,0">
                                                                    <PathFigure.Segments>
                                                                        <PathSegmentCollection>
                                                                            <LineSegment Point="0,15" />
                                                                        </PathSegmentCollection>
                                                                    </PathFigure.Segments>
                                                                </PathFigure>
                                                            </PathFigureCollection>
                                                        </PathGeometry.Figures>
                                                    </PathGeometry>
                                                </Path.Data>
                                            </Path>
                                        </StackPanel>
                                    </DataTemplate>
                                </Setter.Value>
                            </Setter>
                            <Setter TargetName="autofilter" Property="Visibility" Value="Visible"/>
                        </MultiTrigger>
                        <MultiTrigger>
                            <MultiTrigger.Conditions>
                                <Condition SourceName="popupDrag" Property="Tag" Value="True"></Condition>
                                <Condition Property="IsMouseOver" Value="True"></Condition>
                            </MultiTrigger.Conditions>
                            <Setter TargetName="autofilter" Property="ContentTemplate" 
									 >
                                <Setter.Value>
                                    <DataTemplate>
                                        <StackPanel Orientation="Horizontal" Background="{DynamicResource DynamicHeaderHighlightedBackgoundBrush}">

                                            <Path Stroke="{DynamicResource DynamicSeperatorBrush}" StrokeThickness="1" Margin="0,0,3,0">
                                                <Path.Data>
                                                    <PathGeometry>
                                                        <PathGeometry.Figures>
                                                            <PathFigureCollection>
                                                                <PathFigure StartPoint="0,0">
                                                                    <PathFigure.Segments>
                                                                        <PathSegmentCollection>
                                                                            <LineSegment Point="0,15" />
                                                                        </PathSegmentCollection>
                                                                    </PathFigure.Segments>
                                                                </PathFigure>
                                                            </PathFigureCollection>
                                                        </PathGeometry.Figures>
                                                    </PathGeometry>
                                                </Path.Data>
                                            </Path>
                                            <StackPanel Orientation="Horizontal">
                                                <StackPanel VerticalAlignment="Center" HorizontalAlignment="Center">
                                                    <Path Data="M0,0 L6,0 3,3Z" Fill="{DynamicResource AutoFilterBrush}" Stroke="{DynamicResource AutoFilterDarkBrush}" HorizontalAlignment="Center"></Path>
                                                    <Path Stroke="{DynamicResource AutoFilterBrush}" StrokeThickness="2.5" HorizontalAlignment="Center" Margin="0,-2,0,0" >
                                                        <Path.Data>
                                                            <PathGeometry>
                                                                <PathGeometry.Figures>
                                                                    <PathFigureCollection>
                                                                        <PathFigure StartPoint="0,0">
                                                                            <PathFigure.Segments>
                                                                                <PathSegmentCollection>
                                                                                    <LineSegment Point="0,5" />
                                                                                </PathSegmentCollection>
                                                                            </PathFigure.Segments>
                                                                        </PathFigure>
                                                                    </PathFigureCollection>
                                                                </PathGeometry.Figures>
                                                            </PathGeometry>
                                                        </Path.Data>
                                                    </Path>
                                                </StackPanel>
                                                <Path Data="M0,0 L2,0 1,1Z" Fill="{DynamicResource AutoFilterDarkBrush}" Stroke="{DynamicResource AutoFilterDarkBrush}" HorizontalAlignment="Center" VerticalAlignment="Bottom"></Path>
                                            </StackPanel>

                                            <Path Stroke="{DynamicResource DynamicSeperatorBrush}" StrokeThickness="1" Margin="3,0,0,0">
                                                <Path.Data>
                                                    <PathGeometry>
                                                        <PathGeometry.Figures>
                                                            <PathFigureCollection>
                                                                <PathFigure StartPoint="0,0">
                                                                    <PathFigure.Segments>
                                                                        <PathSegmentCollection>
                                                                            <LineSegment Point="0,15" />
                                                                        </PathSegmentCollection>
                                                                    </PathFigure.Segments>
                                                                </PathFigure>
                                                            </PathFigureCollection>
                                                        </PathGeometry.Figures>
                                                    </PathGeometry>
                                                </Path.Data>
                                            </Path>
                                        </StackPanel>
                                    </DataTemplate>
                                </Setter.Value>
                            </Setter>
                            <Setter TargetName="autofilter" Property="Visibility" Value="Visible"/>
                        </MultiTrigger>
                        <MultiTrigger>
                            <MultiTrigger.Conditions>
                                <Condition SourceName="popupDrag" Property="Tag" Value="True"></Condition>
                                <Condition Property="IsMouseOver" Value="False"></Condition>
                            </MultiTrigger.Conditions>
                            <Setter TargetName="autofilter" Property="ContentTemplate" 
									 >
                                <Setter.Value>
                                    <DataTemplate>
                                        <StackPanel Orientation="Horizontal" Background="{DynamicResource DynamicHeaderBackgroundBrush}">

                                            <Path Stroke="{DynamicResource DynamicSeperatorBrush}" StrokeThickness="1" Margin="0,0,3,0">
                                                <Path.Data>
                                                    <PathGeometry>
                                                        <PathGeometry.Figures>
                                                            <PathFigureCollection>
                                                                <PathFigure StartPoint="0,0">
                                                                    <PathFigure.Segments>
                                                                        <PathSegmentCollection>
                                                                            <LineSegment Point="0,15" />
                                                                        </PathSegmentCollection>
                                                                    </PathFigure.Segments>
                                                                </PathFigure>
                                                            </PathFigureCollection>
                                                        </PathGeometry.Figures>
                                                    </PathGeometry>
                                                </Path.Data>
                                            </Path>
                                            <StackPanel Orientation="Horizontal">
                                                <StackPanel VerticalAlignment="Center" HorizontalAlignment="Center">
                                                    <Path Data="M0,0 L6,0 3,3Z" Fill="{DynamicResource AutoFilterBrush}" Stroke="{DynamicResource AutoFilterDarkBrush}" HorizontalAlignment="Center"></Path>
                                                    <Path Stroke="{DynamicResource AutoFilterBrush}" StrokeThickness="2.5" HorizontalAlignment="Center" Margin="0,-2,0,0" >
                                                        <Path.Data>
                                                            <PathGeometry>
                                                                <PathGeometry.Figures>
                                                                    <PathFigureCollection>
                                                                        <PathFigure StartPoint="0,0">
                                                                            <PathFigure.Segments>
                                                                                <PathSegmentCollection>
                                                                                    <LineSegment Point="0,5" />
                                                                                </PathSegmentCollection>
                                                                            </PathFigure.Segments>
                                                                        </PathFigure>
                                                                    </PathFigureCollection>
                                                                </PathGeometry.Figures>
                                                            </PathGeometry>
                                                        </Path.Data>
                                                    </Path>
                                                </StackPanel>
                                                <Path Data="M0,0 L2,0 1,1Z" Fill="{DynamicResource AutoFilterDarkBrush}" Stroke="{DynamicResource AutoFilterDarkBrush}" HorizontalAlignment="Center" VerticalAlignment="Bottom"></Path>
                                            </StackPanel>

                                            <Path Stroke="{DynamicResource DynamicSeperatorBrush}" StrokeThickness="1" Margin="3,0,0,0">
                                                <Path.Data>
                                                    <PathGeometry>
                                                        <PathGeometry.Figures>
                                                            <PathFigureCollection>
                                                                <PathFigure StartPoint="0,0">
                                                                    <PathFigure.Segments>
                                                                        <PathSegmentCollection>
                                                                            <LineSegment Point="0,15" />
                                                                        </PathSegmentCollection>
                                                                    </PathFigure.Segments>
                                                                </PathFigure>
                                                            </PathFigureCollection>
                                                        </PathGeometry.Figures>
                                                    </PathGeometry>
                                                </Path.Data>
                                            </Path>
                                        </StackPanel>
                                    </DataTemplate>
                                </Setter.Value>
                            </Setter>
                            <Setter TargetName="autofilter" Property="Visibility" Value="Visible"/>
                        </MultiTrigger>
                        <!--Sigma-->
                        <MultiTrigger>
                            <MultiTrigger.Conditions>
                                <Condition Property="IsMouseOver" Value="True"></Condition>
                                <Condition SourceName="sigma"   Property="IsMouseOver" Value="True"></Condition>
                            </MultiTrigger.Conditions>
                            <Setter TargetName="sigma" Property="Opacity" Value="1"/>
                        </MultiTrigger>
                        <DataTrigger Binding="{Binding RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=ExtendedGridControl:ExtendedDataGrid},Path=ShowRowSummaries}" Value="False">
                            <Setter TargetName="sigma" Property="Visibility" Value="Collapsed"/>
                        </DataTrigger>

                        <Trigger Property="IsMouseOver" Value="True">
                            <Setter TargetName="headerBorder" Property="Background" 
									Value="{DynamicResource DynamicHeaderHighlightedBackgoundBrush}" />

                        </Trigger>
                        <Trigger Property="IsMouseOver" Value="False">
                            <Setter TargetName="SortArrow" Property="Visibility" Value="Visible" />
                        </Trigger>
                        <!--Sort Indicator-->
                        <MultiTrigger>
                            <MultiTrigger.Conditions>
                                <Condition SourceName="SortArrow" Property="Tag" Value="{x:Null}"></Condition>
                                <Condition Property="SortDirection" Value="Descending"></Condition>
                            </MultiTrigger.Conditions>
                            <Setter TargetName="SortArrow" Property="Visibility" Value="Visible" />

                        </MultiTrigger>
                        <MultiTrigger>
                            <MultiTrigger.Conditions>
                                <Condition SourceName="SortArrow" Property="Tag" Value="{x:Null}"></Condition>
                                <Condition Property="SortDirection" Value="Ascending"></Condition>
                            </MultiTrigger.Conditions>
                            <Setter TargetName="SortArrow" Property="Visibility" Value="Visible" />

                            <Setter TargetName="SortArrow" Property="RenderTransform">
                                <Setter.Value>
                                    <RotateTransform Angle="180" />
                                </Setter.Value>
                            </Setter>
                        </MultiTrigger>
                        <Trigger Property="SortDirection" Value="{x:Null}">
                            <Setter TargetName="SortArrow" Property="Visibility" Value="Collapsed" />
                        </Trigger>
                        <Trigger SourceName="btnClear" Property="IsEnabled" Value="True">
                            <Setter TargetName="popupDrag" Property="Tag" Value="True" />
                        </Trigger>
                        <MultiTrigger>
                            <MultiTrigger.Conditions>
                                <Condition SourceName="SortArrow" Property="Tag" Value="True"></Condition>
                                <Condition Property="SortDirection" Value="Descending"></Condition>
                            </MultiTrigger.Conditions>
                            <Setter TargetName="SortArrow" Property="Data" Value="M0,0 L12,0 6,6Z">
                            </Setter>
                            <Setter TargetName="txtSortOrder" Property="Visibility" Value="Visible" />
                            <Setter TargetName="SortArrow" Property="Visibility" Value="Visible" />
                            <Setter TargetName="SortArrow" Property="Fill" Value="{DynamicResource DynamicSortBrush}"/>
                            <Setter TargetName="SortArrow" Property="Width" Value="12"/>
                            <Setter TargetName="SortArrow" Property="Height" Value="9"/>
                        </MultiTrigger>
                        <MultiTrigger>
                            <MultiTrigger.Conditions>
                                <Condition SourceName="SortArrow" Property="Tag" Value="True"></Condition>
                                <Condition Property="SortDirection" Value="Ascending"></Condition>
                            </MultiTrigger.Conditions>
                            <Setter TargetName="SortArrow" Property="Data" Value="M0,0 L12,0 6,6Z">

                            </Setter>
                            <Setter TargetName="SortArrow" Property="Fill" Value="{DynamicResource DynamicSortBrush}"/>
                            <Setter TargetName="SortArrow" Property="Visibility" Value="Visible" />
                            <Setter TargetName="SortArrow" Property="RenderTransform">
                                <Setter.Value>
                                    <RotateTransform Angle="180" />
                                </Setter.Value>
                            </Setter>
                            <Setter TargetName="txtSortOrder" Property="Visibility" Value="Visible" />
                            <Setter TargetName="SortArrow" Property="Width" Value="12"/>
                            <Setter TargetName="SortArrow" Property="Height" Value="9"/>
                        </MultiTrigger>
                        <Trigger Property="IsPressed" Value="True">
                            <Setter TargetName="headerBorder" Property="Background"
                                Value="{DynamicResource DynamicHeaderPressedBackgroundBrush}" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <!-- DataGridRowSummariesHeader Style -->


    <!-- DataGridRowHeader Gripper -->
    <Style x:Key="RowHeaderGripperStyle" TargetType="{x:Type Thumb}">
        <Setter Property="Height" Value="8"/>
        <Setter Property="Background" Value="Transparent"/>
        <Setter Property="Cursor" Value="SizeNS"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Thumb}">
                    <Border Padding="{TemplateBinding Padding}"
							Background="{TemplateBinding Background}"/>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style x:Key="{x:Type Primitives1:DataGridRowHeader}"
		   TargetType="{x:Type Primitives1:DataGridRowHeader}">
        <Setter Property="Background" Value="{DynamicResource DynamicHeaderBackgroundBrush}" />
        <Setter Property="BorderBrush" Value="{DynamicResource DynamicHeaderBorderBrush}" />
        <EventSetter Event="PreviewMouseLeftButtonDown" Handler="PreviewDataCellMouseLeftButtonDown"/>
        <EventSetter Event="MouseEnter" Handler="CellMouseEnter"/>
        <EventSetter Event="MouseDoubleClick" Handler="RowHeaderMouseDoubleClick"/>
        <EventSetter Event="Click" Handler="RowHeaderClick"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Primitives1:DataGridRowHeader}">
                    <Grid>
                        <Controls:DataGridHeaderBorder 
							x:Name="headerBorder"
							IsSelected="{TemplateBinding IsRowSelected}"
							IsHovered ="{TemplateBinding IsMouseOver}"
							IsPressed="{TemplateBinding IsPressed}"
                            
							Background="{TemplateBinding Background}"
							BorderBrush="{TemplateBinding BorderBrush}"
							BorderThickness="1,0,1,1"
							Padding ="{TemplateBinding Padding}"
							Orientation="Horizontal"
							SeparatorVisibility="{TemplateBinding SeparatorVisibility}"
							SeparatorBrush="{TemplateBinding SeparatorBrush}">
                            <Border BorderBrush="{StaticResource HeaderInnerBorderBrush}"
									BorderThickness="0,1,0,0">
                                <StackPanel Orientation="Horizontal">
                                    <ContentPresenter
										SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
										VerticalAlignment="Center"/>
                                    <Control FontFamily="Arial" FontSize="9"
                                       
										SnapsToDevicePixels="false"
										Visibility="{Binding RelativeSource={RelativeSource AncestorType={x:Type Controls:DataGridRow}}, Path=(Validation.HasError), Converter={StaticResource bool2VisibilityConverter}}"
										Template="{Binding RelativeSource={RelativeSource AncestorType={x:Type Controls:DataGridRow}}, Path=ValidationErrorTemplate}" />
                                </StackPanel>
                            </Border>
                        </Controls:DataGridHeaderBorder>

                        <Path Fill="{DynamicResource DynamicHeaderBorderBrush}" Name="CurrentRowGlyph" VerticalAlignment="Center" Width="6" Height="10"  Stretch="Fill" Visibility="Collapsed" Data="F1 M 511.047,352.682L 511.047,342.252L 517.145,347.467L 511.047,352.682 Z ">
                        </Path>
                        <!--<Image x:Name="EditingRowGlyph" Source="../Images/pen_write.png" Width="12" Height="12"  VerticalAlignment="Center" RenderOptions.BitmapScalingMode="HighQuality" Visibility="Collapsed"/>-->
                        <ContentControl x:Name="EditingRowGlyph" Width="12" Height="12"  VerticalAlignment="Center"   ContentTemplate="{DynamicResource EditingPen}"/>
                        <Thumb x:Name="PART_TopHeaderGripper"
							   VerticalAlignment="Top"
							   Style="{StaticResource RowHeaderGripperStyle}"/>
                        <Thumb x:Name="PART_BottomHeaderGripper"
							   VerticalAlignment="Bottom"
							   Style="{StaticResource RowHeaderGripperStyle}"/>
                    </Grid>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsMouseOver" Value="True">
                            <Setter TargetName="headerBorder" Property="Background" 
									Value="{DynamicResource DynamicHeaderHighlightedBackgoundBrush}" />
                        </Trigger>
                        <Trigger Property="IsPressed" Value="True">
                            <Setter TargetName="headerBorder" Property="Background" 
									Value="{DynamicResource DynamicHeaderPressedBackgroundBrush}" />
                        </Trigger>
                        <MultiDataTrigger>
                            <MultiDataTrigger.Conditions>
                                <Condition Binding="{Binding RelativeSource={RelativeSource AncestorType=Controls:DataGridRow},Path=IsCurrent}"  Value="False"/>
                                <Condition Binding="{Binding RelativeSource={RelativeSource AncestorType=Controls:DataGridRow},Path=IsEditing}" Value="False"/>
                            </MultiDataTrigger.Conditions>
                            <Setter TargetName="CurrentRowGlyph" Property="Visibility" 
									Value="Collapsed" />
                            <Setter TargetName="EditingRowGlyph" Property="Visibility" 
									Value="Collapsed" />
                        </MultiDataTrigger>
                        <MultiDataTrigger>
                            <MultiDataTrigger.Conditions>
                                <Condition Binding="{Binding RelativeSource={RelativeSource AncestorType=Controls:DataGridRow},Path=IsCurrent}"  Value="False"/>
                                <Condition Binding="{Binding RelativeSource={RelativeSource AncestorType=Controls:DataGridRow},Path=IsEditing}" Value="True"/>
                            </MultiDataTrigger.Conditions>
                            <Setter TargetName="CurrentRowGlyph" Property="Visibility" 
									Value="Collapsed" />
                            <Setter TargetName="EditingRowGlyph" Property="Visibility" 
									Value="Visible" />
                        </MultiDataTrigger>
                        <MultiDataTrigger>
                            <MultiDataTrigger.Conditions>
                                <Condition Binding="{Binding RelativeSource={RelativeSource AncestorType=Controls:DataGridRow},Path=IsCurrent}"  Value="True"/>
                                <Condition Binding="{Binding RelativeSource={RelativeSource AncestorType=Controls:DataGridRow},Path=IsEditing}" Value="False"/>
                            </MultiDataTrigger.Conditions>
                            <Setter TargetName="CurrentRowGlyph" Property="Visibility" 
									Value="Visible" />
                            <Setter TargetName="EditingRowGlyph" Property="Visibility" 
									Value="Collapsed" />
                        </MultiDataTrigger>
                        <MultiDataTrigger>
                            <MultiDataTrigger.Conditions>
                                <Condition Binding="{Binding RelativeSource={RelativeSource AncestorType=Controls:DataGridRow},Path=IsCurrent}"  Value="True"/>
                                <Condition Binding="{Binding RelativeSource={RelativeSource AncestorType=Controls:DataGridRow},Path=IsEditing}" Value="True"/>
                            </MultiDataTrigger.Conditions>
                            <Setter TargetName="CurrentRowGlyph" Property="Visibility" 
									Value="Collapsed" />
                            <Setter TargetName="EditingRowGlyph" Property="Visibility" 
									Value="Visible" />
                        </MultiDataTrigger>

                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style TargetType="{x:Type Controls:DataGridCell}">

        <EventSetter Event="MouseEnter" Handler="CellMouseEnter"/>
        <Style.Triggers>
            <Trigger Property="Controls:DataGridCell.IsSelected" Value="True">
                <Setter Property="Background" Value="{DynamicResource DynamicCurrentRowBackgroundBrush}" />
            </Trigger>
        </Style.Triggers>
    </Style>
    <!-- DataGrid Style -->
    <Style  TargetType="ExtendedGridControl:ExtendedDataGrid">
        <Setter Property="RowBackground" Value="{DynamicResource DynamicRowBackgroundBrush}"/>
        <Setter Property="Background" Value="{DynamicResource DynamicDefaultControlBackgroundBrush}"/>
        <Setter Property="Foreground" Value="{DynamicResource DynamicDefaultControlForegroundBrush}"/>
        <Setter Property="BorderBrush" Value="{DynamicResource DynamicDefaultControlBorderBrush}" />
        <Setter Property="HorizontalGridLinesBrush" Value="{DynamicResource DynamicGridLineColorBrush}" />
        <Setter Property="VerticalGridLinesBrush" Value="{DynamicResource DynamicGridLineColorBrush}" />
        <Setter Property="CanUserResizeRows" Value="False"/>
        <Setter Property="AlternatingRowBackground" Value="{DynamicResource DynamicAlternateRowBackgroundBrush}" />
        <Setter Property="EnableColumnVirtualization" Value="True"/>
        <Setter Property="EnableRowVirtualization" Value="True"/>
        <Setter Property="ColumnHeaderStyle" Value="{DynamicResource ColumnHeaderStyle}"/>
        <Setter Property="BorderThickness" Value="1" />
        <!-- This is needed to force DG to have a non-default value.  Otherwise the DGR.DetailsVisibility cannot have a value of VisibleWhenSelected by default. -->
        <Setter Property="RowDetailsVisibilityMode" Value="VisibleWhenSelected" />
        <Setter Property="ScrollViewer.CanContentScroll" Value="true"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="ExtendedGridControl:ExtendedDataGrid">
                    <DockPanel>
                        <Popup x:Name="popupDrag" Width="120" IsHitTestVisible="False" Placement="RelativePoint" AllowsTransparency="True" IsOpen="False">
                            <Border BorderBrush="{DynamicResource DynamicRowDragBorderBrush}" BorderThickness="1"  Background="{DynamicResource DynamicRowDragBrush}"  Opacity="0.9">
                                <StackPanel  Orientation="Horizontal" Margin="4,3,8,3">
                                    <Image Source="../Images/plus.png" Width="16" Height="16" />
                                    <TextBlock
                                                        FontSize="9"
                                                        Foreground="{DynamicResource DynamicDragForegroundBrush}"
                                                        FontWeight="Bold"
                                                        VerticalAlignment="Center"
                                                        Text="{Binding RelativeSource={RelativeSource AncestorType=ExtendedGridControl:ExtendedDataGrid}, Path=DraggedItem[0]}"
                                                        Margin="4,0,0,0">
                                    </TextBlock>
                                </StackPanel>
                            </Border>
                        </Popup>
                        <Border
						Background="{TemplateBinding Background}"
						BorderBrush="{TemplateBinding BorderBrush}"
						BorderThickness="{TemplateBinding BorderThickness}"
						SnapsToDevicePixels="True"
						Padding="{TemplateBinding Padding}">
                            <ScrollViewer Focusable="false" Name="DG_ScrollViewer">
                                <ScrollViewer.Template>
                                    <ControlTemplate TargetType="{x:Type ScrollViewer}">
                                        <Grid>
                                            <!-- Drag and Drop Popup -->

                                            <Grid>
                                                <Grid.RowDefinitions>
                                                    <RowDefinition Height="Auto"/>
                                                    <RowDefinition Height="*"/>
                                                    <RowDefinition Height="Auto"/>
                                                    <RowDefinition Height="Auto"/>
                                                </Grid.RowDefinitions>

                                                <Grid.ColumnDefinitions>
                                                    <ColumnDefinition Width="Auto"/>
                                                    <ColumnDefinition Width="*"/>
                                                    <ColumnDefinition Width="Auto"/>
                                                </Grid.ColumnDefinitions>

                                                <!--Left Column Header Corner -->
                                                <Button Style="{x:Null}" Background="{DynamicResource DynamicHeaderBackgroundBrush}"
											Command="{x:Static Controls:DataGrid.SelectAllCommand}" VerticalContentAlignment="Stretch" HorizontalContentAlignment="Stretch"
											Width="{Binding RelativeSource={RelativeSource AncestorType={x:Type Controls:DataGrid}}, Path=RowHeaderWidth}"
											Focusable="false"
											Visibility="{Binding RelativeSource={RelativeSource AncestorType={x:Type Controls:DataGrid}}, Path=HeadersVisibility, Converter={x:Static Controls:DataGrid.HeadersVisibilityConverter}, ConverterParameter={x:Static Controls:DataGridHeadersVisibility.All}}" >

                                                    <Button.Template>
                                                        <ControlTemplate>
                                                            <Border BorderThickness="1" BorderBrush="{DynamicResource DynamicHeaderBorderBrush}" VerticalAlignment="Stretch" HorizontalAlignment="Stretch">

                                                                <Rectangle VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Fill="{DynamicResource DynamicHeaderBackgroundBrush}">

                                                                </Rectangle>
                                                            </Border>
                                                        </ControlTemplate>
                                                    </Button.Template>
                                                </Button>
                                                <!--Column Headers-->
                                                <DockPanel x:Name="headerPanel" Grid.Row="0" LastChildFill="True"
											Grid.Column="1" >
                                                    <Popup x:Name="columnDragDummy" StaysOpen="False" PlacementTarget="{Binding ElementName=headerPanel}">

                                                    </Popup>
                                                    <Primitives1:DataGridColumnHeadersPresenter DockPanel.Dock="Bottom" x:Name="PART_ColumnHeadersPresenter"
											Visibility="{Binding RelativeSource={RelativeSource AncestorType={x:Type Controls:DataGrid}}, Path=HeadersVisibility, Converter={x:Static Controls:DataGrid.HeadersVisibilityConverter}, ConverterParameter={x:Static Controls:DataGridHeadersVisibility.Column}}">

                                                    </Primitives1:DataGridColumnHeadersPresenter>
                                                    <ContentControl x:Name="groupByContentControl" VerticalContentAlignment="Center" Background="{DynamicResource DynamicHeaderBackgroundBrush}" PreviewMouseDown="RemoveGroupByMouseDown"  HorizontalAlignment="Stretch">
                                                        <ContentControl.Resources>
                                                            <Style TargetType="Primitives1:DataGridColumnHeader">
                                                                <!--<Setter Property="IsHitTestVisible" Value="False"/>-->
                                                                <Setter Property="Height" Value="22"/>
                                                                <Setter Property="Template">
                                                                    <Setter.Value>
                                                                        <ControlTemplate TargetType="{x:Type Primitives1:DataGridColumnHeader}" >
                                                                            <Border BorderBrush="{DynamicResource DynamicHeaderBorderBrush}" BorderThickness="1">

                                                                                <StackPanel Orientation="Horizontal">
                                                                                    <DockPanel  Background="{DynamicResource DynamicHeaderBackgroundBrush}" HorizontalAlignment="Stretch" >
                                                                                        <DockPanel.Resources>
                                                                                            <Style  TargetType="Button">
                                                                                                <Setter Property="OverridesDefaultStyle" Value="True"/>

                                                                                                <Setter Property="Template">
                                                                                                    <Setter.Value>
                                                                                                        <ControlTemplate TargetType="Button">
                                                                                                            <Border Name="border" 
                                                                                                                BorderThickness="1"
                                                                                                                Opacity="0.5"
                                                                                                                BorderBrush="Transparent" 
                                                                                                                CornerRadius="0" 
                                                                                                                Background="{TemplateBinding Background}">
                                                                                                                <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center" />
                                                                                                            </Border>
                                                                                                            <ControlTemplate.Triggers>
                                                                                                                <Trigger Property="IsMouseOver" Value="True">
                                                                                                                    <Setter TargetName="border" Property="Opacity" Value="1" />
                                                                                                                </Trigger>
                                                                                                            </ControlTemplate.Triggers>
                                                                                                        </ControlTemplate>
                                                                                                    </Setter.Value>
                                                                                                </Setter>
                                                                                            </Style>
                                                                                        </DockPanel.Resources>
                                                                                        <TextBlock x:Name="groupName" DockPanel.Dock="Left" Text="{Binding ColumnName}" Width="Auto" Margin="0,0,3,0" VerticalAlignment="Center" Tag="{Binding SortMemberPath}" HorizontalAlignment="Stretch" />
                                                                                        <Button x:Name="btnRemove" DockPanel.Dock="Right" Margin="0,0,2,0"  HorizontalAlignment="Right" Background="Transparent" VerticalAlignment="Center" BorderThickness="1"  BorderBrush="Transparent" Cursor="Hand">

                                                                                            <Canvas Name="canvas" Height="6"  Width="6" >
                                                                                                <Path Stroke="Red" StrokeThickness="1">
                                                                                                    <Path.Data>
                                                                                                        <PathGeometry>
                                                                                                            <PathGeometry.Figures>
                                                                                                                <PathFigure StartPoint="0,0">
                                                                                                                    <LineSegment Point="6,6"/>
                                                                                                                </PathFigure>
                                                                                                                <PathFigure StartPoint="0,6">
                                                                                                                    <LineSegment Point="6,0"/>
                                                                                                                </PathFigure>
                                                                                                            </PathGeometry.Figures>
                                                                                                        </PathGeometry>
                                                                                                    </Path.Data>
                                                                                                </Path>
                                                                                            </Canvas>
                                                                                        </Button>
                                                                                        <Path x:Name="SortArrow"  DockPanel.Dock="Right" Visibility="Collapsed" HorizontalAlignment="Right" Margin="0,0,7,0"   Data="M0,0 L1,0 0.5,1 z" VerticalAlignment="Center"
                                                                                      Width="8" Height="6" Fill="{DynamicResource DynamicSortBrush}" Stretch="Fill" 
                                                                                      RenderTransformOrigin="0.5,0.4" Tag="{x:Null}"/>

                                                                                    </DockPanel>

                                                                                </StackPanel>

                                                                            </Border>
                                                                            <ControlTemplate.Triggers>
                                                                                <Trigger Property="Tag" Value="Ascending">
                                                                                    <Setter TargetName="SortArrow" Property="Visibility" Value="Visible"/>
                                                                                    <Setter TargetName="SortArrow" Property="RenderTransform">
                                                                                        <Setter.Value>
                                                                                            <RotateTransform Angle="180" />
                                                                                        </Setter.Value>
                                                                                    </Setter>
                                                                                </Trigger>
                                                                                <Trigger  Property="Tag"  Value="Descending">
                                                                                    <Setter TargetName="SortArrow" Property="Visibility" Value="Visible"/>
                                                                                </Trigger>
                                                                            </ControlTemplate.Triggers>
                                                                        </ControlTemplate>

                                                                    </Setter.Value>
                                                                </Setter>
                                                                <EventSetter Event="PreviewMouseDown" Handler="GroupByHeaderPreviewMouseDown"/>
                                                            </Style>
                                                        </ContentControl.Resources>
                                                        <StackPanel Orientation="Vertical" MinHeight="30"  VerticalAlignment="Center" Visibility="{Binding RelativeSource={RelativeSource AncestorType=ExtendedGridControl:ExtendedDataGrid}, Path=GroupByControlVisibility}">

                                                            <TextBlock x:Name="txtDragName" Loaded="TxtDragLoaded"  Visibility="Visible"  VerticalAlignment="Stretch" Padding="8">Drag a column header here to group by that column.</TextBlock>

                                                            <DockPanel LastChildFill="True"  HorizontalAlignment="Stretch">
                                                                <Button DockPanel.Dock="Right" Cursor="Hand" Margin="3" x:Name="btnClearGroup" Click="ClearGroupClick" VerticalAlignment="Center" HorizontalAlignment="Right" Visibility="Collapsed">
                                                                    <Image Source="../Images/close.png" Height="12" Width="12"/>
                                                                </Button>
                                                                <ItemsControl DockPanel.Dock="Left" x:Name="group" ItemsSource="{Binding RelativeSource={RelativeSource AncestorType=ExtendedGridControl:ExtendedDataGrid}, Path=GroupByCollection}" HorizontalAlignment="Left" HorizontalContentAlignment="Left" VerticalAlignment="Stretch">
                                                                    <ItemsControl.ItemTemplate>
                                                                        <DataTemplate>
                                                                            <StackPanel Orientation="Horizontal">

                                                                                <Grid HorizontalAlignment="Left" x:Name="Grid"  VerticalAlignment="Stretch" Width="{Binding GridWidth}">
                                                                                    <Grid.RowDefinitions>
                                                                                        <RowDefinition Height="*"/>
                                                                                        <RowDefinition Height="*"/>
                                                                                    </Grid.RowDefinitions>
                                                                                    <Grid.ColumnDefinitions>
                                                                                        <ColumnDefinition Width="*"/>
                                                                                        <ColumnDefinition Width="{Binding GridSecondColumnWidth}"/>
                                                                                    </Grid.ColumnDefinitions>
                                                                                    <Border Grid.Row="0" Grid.Column="0" BorderThickness="0,0,1,0" BorderBrush="{DynamicResource DynamicGridLineColorBrush}">

                                                                                    </Border>
                                                                                    <Border Grid.Row="0" Grid.Column="1" BorderThickness="0,0,0,1" BorderBrush="{DynamicResource DynamicGridLineColorBrush}">

                                                                                    </Border>
                                                                                </Grid>
                                                                                <Primitives1:DataGridColumnHeader Width="Auto" Tag="{Binding SortDirection}" >
                                                                                </Primitives1:DataGridColumnHeader>
                                                                            </StackPanel>
                                                                        </DataTemplate>
                                                                    </ItemsControl.ItemTemplate>
                                                                </ItemsControl>

                                                            </DockPanel>
                                                        </StackPanel>
                                                    </ContentControl>

                                                </DockPanel>

                                                <!--DataGrid content-->
                                                <DockPanel Grid.Row="1" VerticalAlignment="Top" Grid.ColumnSpan="2" LastChildFill="True" >

                                                    <ContentControl x:Name="footerControlPlacer" DockPanel.Dock="Bottom"  HorizontalAlignment="Stretch">
                                                        <Border BorderBrush="{DynamicResource DynamicHeaderBorderBrush}"  BorderThickness="1" VerticalAlignment="Bottom" >
                                                            <StackPanel Orientation="Horizontal" >

                                                                <Border BorderBrush="{DynamicResource DynamicHeaderBorderBrush}" BorderThickness="0,0.5,1,0.5" HorizontalAlignment="Left"	Width="{Binding RelativeSource={RelativeSource AncestorType=Controls:DataGrid},Path=RowHeaderWidth}">
                                                                    <Rectangle x:Name="rowSummariesHeader" Style="{x:Null}" HorizontalAlignment="Stretch" Fill="{DynamicResource DynamicHeaderBackgroundBrush}"
										                                    VerticalAlignment="Stretch"
											                                Focusable="false"
										                                >

                                                                    </Rectangle>

                                                                </Border>
                                                                <ContentControl x:Name="mainFooter" VerticalAlignment="Stretch" HorizontalAlignment="Left" ContentTemplate="{Binding RelativeSource={RelativeSource AncestorType=ExtendedGridControl:ExtendedDataGrid},Path=FooterDataTemplate}">

                                                                </ContentControl>



                                                            </StackPanel>
                                                        </Border>
                                                    </ContentControl>

                                                    <StackPanel VerticalAlignment="Stretch" HorizontalAlignment="Left" DockPanel.Dock="Bottom" Orientation="Horizontal" x:Name="summaryRow">
                                                        <Border BorderBrush="{DynamicResource DynamicHeaderBorderBrush}" BorderThickness="0,0.5,1,0.5" HorizontalAlignment="Left"	Width="{Binding RelativeSource={RelativeSource AncestorType=Controls:DataGrid},Path=RowHeaderWidth}">
                                                            <Rectangle x:Name="footerHeader" Style="{x:Null}" HorizontalAlignment="Stretch" Fill="{DynamicResource DynamicHeaderBackgroundBrush}"
										                        VerticalAlignment="Stretch"
											                    Focusable="false"
										                     >

                                                            </Rectangle>

                                                        </Border>
                                                    </StackPanel>

                                                    <ScrollContentPresenter x:Name="PART_ScrollContentPresenter"  CanContentScroll="{TemplateBinding CanContentScroll}" />
                                                    
                                                </DockPanel >
                                                <!--added a grid here for the vertical scroll bar to resize when row freezes-->
                                                <Grid Grid.Row="1" Grid.Column="2">
                                                    <Grid.RowDefinitions>
                                                        <RowDefinition Height="{Binding RelativeSource={RelativeSource AncestorType={x:Type Base:CustomDataGrid}}, Path=NonFrozenRowsViewportVerticalOffset}"/>
                                                        <RowDefinition Height="*"/>
                                                    </Grid.RowDefinitions>
                                                    <ScrollBar Grid.Row="1"
                                                         Name="PART_VerticalScrollBar"
                                                         Orientation="Vertical"
                                                         Maximum="{TemplateBinding ScrollableHeight}"
                                                         ViewportSize="{TemplateBinding ViewportHeight}"
                                                         Value="{Binding Path=VerticalOffset, RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}"
                                                         Visibility="{TemplateBinding ComputedVerticalScrollBarVisibility}"/>
                                                </Grid>
                                                <StackPanel DockPanel.Dock="Bottom" Grid.Row="2" Grid.ColumnSpan="3" Orientation="Horizontal" Style="{x:Null}">
                                                    <Border BorderBrush="{DynamicResource DynamicHeaderBorderBrush}" BorderThickness="0,0.5,1,0.5" HorizontalAlignment="Left"	Width="{Binding RelativeSource={RelativeSource AncestorType=Controls:DataGrid},Path=RowHeaderWidth}">
                                                            <Rectangle x:Name="rowSummariesHeader1" Style="{x:Null}" HorizontalAlignment="Stretch"
										                            VerticalAlignment="Stretch" Fill="{DynamicResource DynamicHeaderBackgroundBrush}"
											                        Focusable="false">

                                                            </Rectangle>
                                                        </Border>
                                                    <Controls:DataGrid x:Name="rowSummariesGrid" ScrollViewer.HorizontalScrollBarVisibility="Hidden" Style="{x:Null}" BorderThickness="0,1,1,1" BorderBrush="{DynamicResource DynamicHeaderBorderBrush}" Loaded="RowSummariesGridLoaded" HeadersVisibility="Column" CanUserAddRows="False" CanUserDeleteRows="False" CanUserReorderColumns="False" CanUserResizeColumns="False" CanUserResizeRows="False" CanUserSortColumns="False" IsReadOnly="True"
                                                                       Width="{Binding RelativeSource={RelativeSource AncestorType=ExtendedGridControl:ExtendedDataGrid},Path=ActualWidth}" RowHeight="0">
                                                    </Controls:DataGrid >
                                                </StackPanel>
                                                <Grid Grid.Row="3" Grid.Column="1">
                                                    <Grid.ColumnDefinitions>
                                                        <ColumnDefinition Width="{Binding RelativeSource={RelativeSource AncestorType={x:Type Controls:DataGrid}}, Path=NonFrozenColumnsViewportHorizontalOffset}"/>
                                                        <ColumnDefinition Width="*"/>
                                                    </Grid.ColumnDefinitions>
                                                   
                                                    <ScrollBar 
												Grid.Column="1" VerticalAlignment="Bottom" 
												Name="PART_HorizontalScrollBar"
												Orientation="Horizontal"
												Maximum="{TemplateBinding ScrollableWidth}"
												ViewportSize="{TemplateBinding ViewportWidth}"
												Value="{Binding Path=HorizontalOffset, RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}"
												Visibility="{TemplateBinding ComputedHorizontalScrollBarVisibility}"  Scroll="OnScroll" />
                                                </Grid>

                                            </Grid>
                                            <Rectangle  Fill="{DynamicResource AutoFilterBrush}"   Width="7" Loaded="DummyGridSplitterLoaded"  Visibility="Collapsed" HorizontalAlignment="Left">

                                            </Rectangle>
                                            <Grid Loaded="GridSplitterGridLoaded">
                                                <Grid.ColumnDefinitions>
                                                    <ColumnDefinition Width="0"/>
                                                    <ColumnDefinition Width="Auto"/>
                                                    <ColumnDefinition/>
                                                </Grid.ColumnDefinitions>

                                                <GridSplitter x:Name="gridSplitter" PreviewMouseDown="GridSplitterMouseDown" ShowsPreview="False" PreviewMouseUp="GridSplitterMouseUp"  Cursor="SizeWE"   Grid.Column="1" Width="7" Loaded="GridSplitterLoaded" ResizeBehavior="PreviousAndNext" Visibility="Visible">
                                                    <GridSplitter.Resources>
                                                        <Style TargetType="{x:Type GridSplitter}">

                                                            <Setter Property="PreviewStyle">
                                                                <Setter.Value>
                                                                    <Style>
                                                                        <Setter Property="Control.Template">
                                                                            <Setter.Value>
                                                                                <ControlTemplate>
                                                                                    <Rectangle Fill="#80000000"/>
                                                                                </ControlTemplate>
                                                                            </Setter.Value>
                                                                        </Setter>
                                                                    </Style>
                                                                </Setter.Value>
                                                            </Setter>
                                                            <Setter Property="Template">
                                                                <Setter.Value>
                                                                    <ControlTemplate TargetType="{x:Type GridSplitter}">
                                                                        <Border 
                                                                            BorderThickness="{TemplateBinding BorderThickness}"/>
                                                                    </ControlTemplate>
                                                                </Setter.Value>
                                                            </Setter>
                                                        </Style>
                                                    </GridSplitter.Resources>
                                                    <GridSplitter.Template>
                                                        <ControlTemplate TargetType="{x:Type GridSplitter}">
                                                            <Grid VerticalAlignment="Stretch">
                                                                <Button  Background="#DDE0E3"  VerticalAlignment="Stretch" VerticalContentAlignment="Top" Content="⁞" BorderBrush="Transparent" BorderThickness="0"  Margin="-0.3,0,0,0"/>
                                                                <Rectangle  Fill="Transparent" VerticalAlignment="Stretch"/>
                                                            </Grid>
                                                        </ControlTemplate>
                                                    </GridSplitter.Template>
                                                </GridSplitter>


                                            </Grid>
                                            <Rectangle x:Name="rowSplitter" Loaded="RowSplitterLoaded" Fill="{DynamicResource AutoFilterBrush}" Height="2" HorizontalAlignment="Stretch"  VerticalAlignment="Top" Visibility="Collapsed">

                                            </Rectangle>
                                        </Grid>
                                    </ControlTemplate>
                                </ScrollViewer.Template>
                                <ItemsPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
                            </ScrollViewer>
                        </Border>
                    </DockPanel>

                </ControlTemplate>
            </Setter.Value>
        </Setter>

        <!--Event Setters-->
        <EventSetter Event="Loaded" Handler="GridLoaded"/>
        <EventSetter Event="MouseMove" Handler="GridMouseMove"/>
        <EventSetter Event="PreviewMouseLeftButtonUp" Handler="GridPreviewMouseLeftButtonUp"/>
        <EventSetter Event="MouseLeave" Handler="GridMouseLeave"/>
        <Style.Triggers>
            <Trigger Property="IsGrouping" Value="true">
                <Setter Property="ScrollViewer.CanContentScroll" Value="false"/>
            </Trigger>
        </Style.Triggers>

    </Style>

</ResourceDictionary>